package com.situ.object.dao.impl;

import com.situ.object.dao.TeacherDao;
import com.situ.object.entity.Teacher;
import com.situ.object.utils.DBUtil;

import java.util.List;

public class TeacherDaoImpl implements TeacherDao {
    DBUtil dbUtil = new DBUtil();

    //根据教师名查询教师信息
    @Override
    public Teacher selectByTeacherName(String teacher_name) {
        String sql = "select teacherId,teacherName,studentPassword,teacherSex,teacherAge,phone,title from Teacher where teacher_name = ?";
        return dbUtil.queryOne(Teacher.class,sql,teacher_name);
    }

    //添加教师信息
    @Override
    public int addTeacher(Teacher teacher) {
        String sql = "INSERT INTO manage_system.teacher(teacherName, studentPassword, teacherSex, teacherAge, phone, title) VALUES (?,?,?,?,?,?)";
        return dbUtil.update(sql,teacher.getTeacherName(),teacher.getStudentPassword(),teacher.getTeacherSex(),teacher.getTeacherAge(),teacher.getPhone(),teacher.getTitle());
    }

    //删除教师信息
    @Override
    public int deleteTeacher(Integer id) {
        String sql = "delete from teacher where teacherId = ?";
        return dbUtil.update(sql,id);
    }

    @Override
    public int deleteByName(String name) {
        String sql = "delete from teacher where teacherName = ?";
        return dbUtil.update(sql,name);
    }

    @Override
    public List<Teacher> selectAll() {
        String sql = "select * from teacher";
        return dbUtil.query(Teacher.class,sql);
    }

    @Override
    public int edit(Teacher teacher) {
        String sql = "UPDATE manage_system.teacher SET teacherName = ?, studentPassword = ?, teacherSex = ?, teacherAge = ?, phone = ?, title = ? WHERE teacherId = ? ";
        return dbUtil.update(sql,teacher.getTeacherName(),teacher.getStudentPassword(),teacher.getTeacherSex(),teacher.getTeacherAge(),teacher.getPhone(),teacher.getTitle(),teacher.getTeacherId());
    }

}

